//
//  UserViewController.swift
//  GZMarathon
//
//  Created by apple on 2021/11/11.
//

import UIKit
import MJRefresh
class UserViewController: UIViewController {

    @IBOutlet weak var tab: UITableView!
    
    var dataSource: [GZMaintainList] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "联系运维"
        tab.removeMoreLine()
        confTable()
    }
    
    func confTable(){
        tab.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
            self?.getFaqList()
        })
        tab.mj_header?.beginRefreshing()
    }
    
    func getFaqList(){
        ApiLoadingProvider.request(EBAPI.getMaintainList(page: "1", pageSize: "20"), model: GZMaintainData.self) {[weak self] model, isSuc in
            
            self?.tab.mj_header?.endRefreshing()
            guard let dt = model else{
                return
            }
            self?.dataSource = dt.data
            self?.tab.reloadData()
        }
    }
}

extension UserViewController:UITableViewDelegate,UITableViewDataSource{

    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 56
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "UserTableViewCell", for: indexPath) as! UserTableViewCell
        let maitain = dataSource[indexPath.row]
        cell.name.text = maitain.account_name
        cell.iphone.text = maitain.account_phonenum
        cell.connectBt.tag = 1
        cell.connectBt.addTarget(self, action: #selector(connectUserClick(bt:)), for: .touchUpInside)
        return cell
    }
    
    @objc func connectUserClick(bt:UIButton){
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
}
